<template>
  <div class="common-switch">
    <div
      v-for="item in options"
      :key="item.value"
      :class="['common-switch__item', active === item.value && 'is-active']"
      @tap="onSelect(item.value)"
    >
      {{ item.label }}
    </div>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "common-switch",
});

withDefaults(
  defineProps<{
    options: { label: string; value: string | number }[];
  }>(),
  {
    options: () => [],
  }
);

const active = defineModel<string | number>({ default: "" });

const onSelect = (value: string | number) => {
  if (active.value === value) return;

  active.value = value;
};
</script>

<style lang="less">
.common-switch {
  display: flex;
  align-items: center;
  background: #ffe3d9;
  border-radius: 32px;
  padding: 4px;
  box-sizing: border-box;
  &__item {
    font-weight: 400;
    font-size: 32px;
    color: #ff5a5a;
    line-height: 44px;
    padding: 6px 22px;
    box-sizing: border-box;
    border-radius: inherit;
    transition: all 0.3s ease-in-out;
    &.is-active {
      background: #ffffff;
      font-weight: 500;
      color: #000000;
    }
  }
}
</style>
